#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>

using namespace std;

// 判断a是否是b的后缀
bool is_suffix(const string& a, const string& b) {
    if (a.size() > b.size()) return false;
    return b.substr(b.size() - a.size()) == a;
}

int main() {
    int n;
    cin >> n;

    map<string, set<string>> phoneBook;

    for (int i = 0; i < n; ++i) {
        string name;
        int cnt;
        cin >> name >> cnt;

        for (int j = 0; j < cnt; ++j) {
            string number;
            cin >> number;
            phoneBook[name].insert(number);
        }
    }

    map<string, vector<string>> result;

    // 处理每个朋友的电话号码（使用传统迭代器）
    for (map<string, set<string>>::iterator it = phoneBook.begin(); it != phoneBook.end(); ++it) {
        const string& name = it->first;
        const set<string>& numbers = it->second;

        // 转换为 vector 方便处理
        vector<string> nums(numbers.begin(), numbers.end());
        vector<string> filtered;

        for (const string& num : nums) {
            bool keep = true;
            for (const string& other : nums) {
                if (num != other && is_suffix(num, other)) {
                    keep = false;
                    break;
                }
            }
            if (keep) filtered.push_back(num);
        }
 // 使用自定义排序规则：先按长度，再按字典序
        sort(filtered.begin(), filtered.end(), [](const string& a, const string& b) {
            if (a.length() != b.length())
                return a.length() < b.length();
            return a < b;
        });
        result[name] = filtered;
    }

    // 输出结果
    cout << result.size() << endl;
    for (map<string, vector<string>>::iterator it = result.begin(); it != result.end(); ++it) {
        const string& name = it->first;
        const vector<string>& numbers = it->second;

        cout << name << " " << numbers.size();
        for (const string& num : numbers) {
            cout << " " << num;
        }
        cout << endl;
    }

    return 0;
}